package db.tables;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import com.db.Table;

import db.beans.M_CurrencyBean;

public class M_CurrencyTable extends Table {

	public static final String TABLE_NAME = "M_CURRENCY";
	public static final String COL_CURRENCY_ID = "CURRENCY_ID";
	public static final String COL_CURRENCY_NAME = "CURRENCY_NAME";

	public static final String F_COL_CURRENCY_ID = TABLE_NAME + "." + "CURRENCY_ID";
	public static final String F_COL_CURRENCY_NAME = TABLE_NAME + "." + "CURRENCY_NAME";

	public static M_CurrencyBean[] selectAll(Connection conn) throws SQLException {
		final String sql = "SELECT "
				+ COL_CURRENCY_ID + ","
				+ COL_CURRENCY_NAME
				+ " FROM " + TABLE_NAME;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		Vector<M_CurrencyBean> v = new Vector<M_CurrencyBean>();
		try {
			stmt = conn.prepareStatement(sql);
			rs = stmt.executeQuery();
			int i;
			while (rs.next()) {
				i = 0;
				M_CurrencyBean rec = new M_CurrencyBean();
				rec.setCurrencyId(rs.getInt(++i));
				rec.setCurrencyName(rs.getString(++i));
				v.add(rec);
			}
		} finally {
			if (rs != null) {
				rs.close();
			}

			if (stmt != null) {
				stmt.close();
			}
		}
		return (M_CurrencyBean[]) v.toArray(new M_CurrencyBean[v.size()]);
	}
}
